package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.HeroSkillInfo;
import liumengbaio.lolzhangyoubao.Activity.utils.HeroSkillsUtils;
import liumengbaio.lolzhangyoubao.R;

public class AddSkillsActivity extends AppCompatActivity implements View.OnClickListener {
    private List<HeroSkillInfo> heroSkillInfoList;
    private HeroSkillInfo heroSkillInfo_Q, heroSkillInfo_W, heroSkillInfo_E, heroSkillInfo_R;
    private ImageView iv_skill_Q, iv_skill_W, iv_skill_E, iv_skill_R;
    private int flag_Q = 0, flag_W = 0, flag_E = 0, flag_R = 0, flag;
    private ImageView imageViews1, imageViews2, imageViews3, imageViews4, imageViews5,
            imageViews6, imageViews7, imageViews8, imageViews9, imageViews10,
            imageViews14, imageViews15, imageViews16, imageViews17, imageViews18,
            imageViews11, imageViews12, imageViews13;
    private List<ImageView> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_skills);
        initView();
        initData();
    }

    private void initData() {
        iv_skill_Q.setOnClickListener(this);
        iv_skill_W.setOnClickListener(this);
        iv_skill_E.setOnClickListener(this);
        iv_skill_R.setOnClickListener(this);
    }

    private void initView() {
        String role_id = getIntent().getStringExtra("role_id");
        String name = getIntent().getStringExtra("nicker_name");
        findViewById(R.id.edit_head_left_title).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        heroSkillInfoList = HeroSkillsUtils.getSummonerSkillsInfoList(AddSkillsActivity.this);
        for (int i = 1; i < heroSkillInfoList.size(); i++) {
            if (role_id.equals(heroSkillInfoList.get(i).getRole_id()) && heroSkillInfoList.get(i).getKey().equals("Q")) {
                heroSkillInfo_Q = heroSkillInfoList.get(i);

            }
            if (role_id.equals(heroSkillInfoList.get(i).getRole_id()) && heroSkillInfoList.get(i).getKey().equals("W")) {
                heroSkillInfo_W = heroSkillInfoList.get(i);

            }
            if (role_id.equals(heroSkillInfoList.get(i).getRole_id()) && heroSkillInfoList.get(i).getKey().equals("E")) {
                heroSkillInfo_E = heroSkillInfoList.get(i);

            }
            if (role_id.equals(heroSkillInfoList.get(i).getRole_id()) && heroSkillInfoList.get(i).getKey().equals("R")) {
                heroSkillInfo_R = heroSkillInfoList.get(i);
            }
        }
        iv_skill_Q = (ImageView) findViewById(R.id.iv_skill_Q);
        iv_skill_W = (ImageView) findViewById(R.id.iv_skill_W);
        iv_skill_E = (ImageView) findViewById(R.id.iv_skill_E);
        iv_skill_R = (ImageView) findViewById(R.id.iv_skill_R);
        imageViews1 = (ImageView) findViewById(R.id.iv_add_skill_1);
        imageViews2 = (ImageView) findViewById(R.id.iv_add_skill_2);
        imageViews3 = (ImageView) findViewById(R.id.iv_add_skill_3);
        imageViews4 = (ImageView) findViewById(R.id.iv_add_skill_4);
        imageViews5 = (ImageView) findViewById(R.id.iv_add_skill_5);
        imageViews6 = (ImageView) findViewById(R.id.iv_add_skill_6);
        imageViews7 = (ImageView) findViewById(R.id.iv_add_skill_7);
        imageViews8 = (ImageView) findViewById(R.id.iv_add_skill_8);
        imageViews9 = (ImageView) findViewById(R.id.iv_add_skill_9);
        imageViews10 = (ImageView) findViewById(R.id.iv_add_skill_10);
        imageViews11 = (ImageView) findViewById(R.id.iv_add_skill_11);
        imageViews12 = (ImageView) findViewById(R.id.iv_add_skill_12);
        imageViews13 = (ImageView) findViewById(R.id.iv_add_skill_13);
        imageViews14 = (ImageView) findViewById(R.id.iv_add_skill_14);
        imageViews15 = (ImageView) findViewById(R.id.iv_add_skill_15);
        imageViews16 = (ImageView) findViewById(R.id.iv_add_skill_16);
        imageViews17 = (ImageView) findViewById(R.id.iv_add_skill_17);
        imageViews18 = (ImageView) findViewById(R.id.iv_add_skill_18);
        list.add(imageViews1);
        list.add(imageViews2);
        list.add(imageViews3);
        list.add(imageViews4);
        list.add(imageViews5);
        list.add(imageViews6);
        list.add(imageViews7);
        list.add(imageViews8);
        list.add(imageViews9);
        list.add(imageViews10);
        list.add(imageViews11);
        list.add(imageViews12);
        list.add(imageViews13);
        list.add(imageViews14);
        list.add(imageViews15);
        list.add(imageViews16);
        list.add(imageViews17);
        list.add(imageViews18);
        Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_Q.getPic_url()).into(iv_skill_Q);
        Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_W.getPic_url()).into(iv_skill_W);
        Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_E.getPic_url()).into(iv_skill_E);
        Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_R.getPic_url()).into(iv_skill_R);
        flag = 0;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_skill_Q:
                if (flag_Q < 6) {
                    flag_Q += 1;
                    Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_Q.getPic_url()).into(list.get(flag));
                    flag++;
                }
                break;
            case R.id.iv_skill_W:
                if (flag_Q < 6) {
                    flag_W += 1;
                    Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_W.getPic_url()).into(list.get(flag));
                    flag += 1;
                }
                break;
            case R.id.iv_skill_E:
                if (flag_Q < 6) {
                    flag_E += 1;
                    Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_E.getPic_url()).into(list.get(flag));
                    flag += 1;
                }
                break;
            case R.id.iv_skill_R:
                if (flag_Q < 4) {
                    flag_R += 1;
                    Picasso.with(AddSkillsActivity.this).load(heroSkillInfo_R.getPic_url()).into(list.get(flag));
                    flag += 1;
                }
                break;
        }
    }
}
